<table>
<tr>
<td>
<?php if(!empty($thongkenamnu)){?>
<table id='tables'>
<tr>
<th></th>
<th>Nam</th>
<th>Nữ</th>
<th>Tổng số</th>
</tr>
<tr>
<td>Số lượng</td>
<?php $tongso=0; $nu=0;$nam=0;?>
<?php foreach ($thongkenamnu as $thonhkenn):?>
<?php if($thonhkenn[$tenloaidv]['phai']=='Nam'){?>
<?php $nam= !empty($thonhkenn[0]['soluong'])?$thonhkenn[0]['soluong']:0?>
<?php $tongso += $nam;?>
<?php }else{?>
<?php $nu= !empty($thonhkenn[0]['soluong'])?$thonhkenn[0]['soluong']:0?>
<?php $tongso += $nu;?>
<?php }?>
<?php endforeach;?>
<td><?php echo $nam?></td>
<td><?php echo $nu?></td>
<td><?php echo $tongso?></td>
</tr>
</table>
<?php }?>
</td>
<td>
<?php if(!empty($thongkethanhnien)){?>
<table id='tables'>
<tr>
<th></th>
<th>Thanh niên</th>
<th>Đoàn viên</th>
<th>Đảng viên</th>
<th>Tổng số</th>
</tr>
<tr>
<td>Số lượng</td>
<?php $tongso = 0?>
<?php $tongso += $thongkethanhnien[0][0]['soluong'];?>
<td><?php echo $thongkethanhnien[0][0]['soluong']?></td>
<?php $tongso += $thongkedoanvien[0][0]['soluong'];?>
<td><?php echo $thongkedoanvien[0][0]['soluong']?></td>
<?php $tongso += $thongkedangvien[0][0]['soluong'];?>
<td><?php echo $thongkedangvien[0][0]['soluong']?></td>
<td><?php echo $tongso?></td>
</tr>
</table>
<?php }?>
</td>
</tr>
</table>
<?php echo $form->create('Chidoansv',array('url'=>array('controller'=>'users','action'=>'themaccount',$loaidv,$chidoansv_id),'onsubmit'=>'return validate();'));?>
<table id='tables'>
<tr>
<th rowspan=2><?php echo $form->input('checkall',array('class'=>'checkall','label'=>false,'type'=>'checkbox'));?></th>
<th rowspan=2>STT</th>
<th rowspan=2>Họ tên</th>
<th rowspan=2>Chức vụ</th>
<th rowspan=2>Ngày sinh</th>
<th rowspan=2>Nơi sinh</th>
<th rowspan=2>Địa chỉ</th>
<th colspan=3>Quê quán</th>
<th rowspan=2>Phái</th>
<th rowspan=2>Dân tộc</th>
<th rowspan=2>Tôn giáo</th>
<th rowspan=2>Số điện thoại</th>
<th rowspan=2>Email</th>
<th rowspan=2>Đoàn viên/TTđoàn/Thanh niên</th>
<th rowspan=2>Trưởng thành đoàn</th>
<th rowspan=2>Chi đoàn</th>
<th rowspan=2>Thao tác</th>
</tr>
<tr>
<th>Phường/xã</th>
<th>Quận/Huyện</th>
<th>Tỉnh/TP</th>
</tr>
<?php if(!empty($doanviens)){?>
<?php $i=1;?>
<?php foreach ($doanviens as $doanvien):?>
<tr>
<td><?php echo $form->input('checkbox',array('class'=>'check','name'=>'data[checkbox]['.$doanvien[$tenloaidv][$maso].']','id'=>'checkall','label'=>false,'type'=>'checkbox'));//(in_array($doanvien[$tenloaidv][$maso], $coacc)?'':$form->input('checkbox',array('class'=>'check','name'=>'data[checkbox]['.$doanvien[$tenloaidv][$maso].']','id'=>'checkall','label'=>false,'type'=>'checkbox')));?></td>
<td><?php echo $i;?></td>

<td><?php echo $doanvien[$tenloaidv]['name'];?></td>
<td><?php echo (isset($chucvus[$doanvien[$tenloaidv]['id']])?$chucvus[$doanvien[$tenloaidv]['id']]:'');?></td>
<td><?php echo ($doanvien[$tenloaidv]['ngaysinh']!='0000-00-00'?date('d-m-Y',strtotime($doanvien[$tenloaidv]['ngaysinh'])):'');?></td>
<td><?php echo $doanvien[$tenloaidv]['noisinh'];?></td>
<td><?php echo $doanvien[$tenloaidv]['diachi'];?></td>
<td><?php echo $doanvien[$tenloaidv]['Phuongxa']['tenphuongxa']?></td>
<td>
<?php
foreach ($quanhuyens as $qh)
{
	if($qh['Quanhuyen']['id']==$doanvien[$tenloaidv]['Phuongxa']['quanhuyen_id'])
		$qq = $qh;
}
	echo $qq['Quanhuyen']['tenquanhuyen'];
?>
</td>
<td>
<?php
echo $qq['Tinhtp']['tentinhtp'];
?>
</td>
<td><?php echo $doanvien[$tenloaidv]['phai'];?></td>
<td><?php echo $doanvien[$tenloaidv]['Dantoc']['tendantoc'];?></td>
<td><?php echo $doanvien[$tenloaidv]['Tongiao']['tentongiao'];?></td>
<td><?php echo $doanvien[$tenloaidv]['sodienthoai'];?></td>
<td><?php echo $doanvien[$tenloaidv]['email'];?></td>
<td><?php echo ($doanvien[$tenloaidv]['ngayvaodang']!== NULL && $doanvien[$tenloaidv]['ngayvaodang']!= '0000-00-00')?'Đảng viên':(($doanvien[$tenloaidv]['ngayvaodoan']!== null && $doanvien[$tenloaidv]['ngayvaodoan']!='0000-00-00')?'Đoàn viên':'Thanh niên')?></td>
<td><?php echo ($doanvien[$tenloaidv][$ttdoan]===NULL ||$doanvien[$tenloaidv][$ttdoan]=='0000-00-00'?'':'Đã trưởng thành đoàn'); ?></td>
<td><?php echo $doanvien['Chidoansv']['tenchidoan'];?></td>
<td><?php echo $html->link('Sửa',array('controller'=>($tenloaidv=='Sinhvien'?'sinhviens':'canbos'),'action'=>'edit',$doanvien[$tenloaidv]['id']));
		//echo $html->link('Xóa',array('controller'=>($tenloaidv=='Sinhvien'?'sinhviens':'canbos'),'action'=>'delete',$doanvien[$tenloaidv]['id']))?>
</td>
</tr>
<?php $i+=1;?>
<?php endforeach;?>
<?php }?>
</table>
<?php if(!empty($doanviens)){?>
	<p>
	<?php
	 $paginator->options = array('url'=>array('controller'=>'chidoansvs','action'=>'caychidoan',$loaidv,$chidoansv_id));
	echo $this->Paginator->counter(array(
	'format' => __('Trang %page%/%pages%, hiện có %count% mẫu tin', true)
	));
	?>	</p>

	<div class="paging">
		<?php echo $this->Paginator->prev('<< ' . __('Trước', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('Sau', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
	<?php }?>
	<?php echo $form->input('select',array('name'=>'data[Chidoansv][select]','id'=>'select','label'=>'Thao tác','type'=>'select','options'=>array('ttk'=>'Tạo tài khoản','xoasv'=>'Xóa Sinh Viên','cdht'=>'Xóa Chi đoàn hiện tại'),'empty'=>'--Chọn Thao tác--'));?>
	<?php echo $form->end(' Thực hiện ');?>
<script>
function validate()
{
	if($('#select').val()!='cdht' && $('#select').val() !='')
	{
		$checked=0;
		$("input:checkbox").each(function(){
											if ($(this).is(":checked") && $(this).prop('class')!='checkall')
													$checked++;
											});
		if ($checked==0)
		{
			alert('Bạn chưa chọn đoàn viên nào');
			return false;			
		}
		else
		{if($('#select').val()=='xoasv')
			{
			if(confirm('Bạn muốn xóa sinh viên này?'))
				return true;
			else
				return false;
			}
			else return true;
		}
	}
	else if($('#select').val()=='cdht')
	{
		if(confirm('Bạn muốn xóa Chi đoàn này?'))
			return true;
		else
			return false;
	}
	else
	{alert('Bạn chưa chọn thao tác');
		return false;}
}

$('.checkall').click(function(){
	if($(this).prop('class')=='checkall')
	{
		if($(this).prop('checked')==true)
		{
			$('.check').prop('checked',true);
		}
		else
		{
			$('.check').prop('checked',false);
		}
	}
});
</script>